(function($) {
    var init={
    		"bFilter": true,//搜索框
    		"aoColumns" : [
                           {"data" : "aname"},
                           { "data" : "startAtToString",},
                           {"data" : "endAtToString"},
                           {"data" : "cost"},
                           {"data" : "pv"},
                           {"data" : "pc"},
                           {"data" : "clickRate"},
                           {"data" : "avgCost"},
                           {"data" : "avgCostView"},
                           {
                           	"targets": [9],
                               "data": "id",
                               "render": function(data, type, full) {
                                 return "<a href='/ads/adId/edit?id=" + data + "'>统计</a>";
                                 }
                              },
                       ],
             "sAjaxSource": "/ads/ads_list",//这个是请求的地址
    }
    $(function(){
        $.extend(init,dataTableInit)
        $("#adsTable").dataTable(init)
    })
    
    //在表单外自定义全局搜索框
    $("#search").on( 'keyup click', function () {
    	  $("#adsTable").DataTable().search(
    		        $('#search').val()
    		    ).draw();
    } );
    
    $("#time").on('click',function(){
    	var time=$('#start').val()+","+ $('#end').val();
    	 $('#adsTable').DataTable().column( 0 ).search(
    			 time
 		    ).draw();
    });
})($);

(function($) {
    var init={
    		"bFilter": true,//搜索框
    		"aoColumns" : [
    		               {"data" : "rptDateToString"},
                           {
                              	"targets": [1],
                                  "data": "id",
                                  "render": function(data, type, full) {
                                    return "<a href='/ads/adId/edit?id=" + data + "'>"+full.aname+"</a>";
                                    }
                                 },
                           {"data" : "pv"},
                           {"data" : "pc"},
                           {"data" : "clickRate"},
                           {"data" : "avgCost"},
                           {"data" : "avgCostView"},
                           {"data" : "cost"},
                       ],
             "sAjaxSource": "/reports/ads",//这个是请求的地址
    }
    $(function(){
        $.extend(init,dataTableInit)
        $("#rptAdsTable").dataTable(init)
    })
    
    //在表单外自定义全局搜索框
    $("#search").on( 'keyup click', function () {
    	  $("#rptAdsTable").DataTable().search(
    		        $('#search').val()
    		    ).draw();
    } );
    
    /*自定义某一列的搜索框 根据 参数 >i< 决定*/
  /*  $("#search").on( 'keyup click', function () {
  	  $('#adsTable').DataTable().column( i ).search(
  		        $('#search').val()
  		    ).draw();
  } );*/

    $("#time").on('click',function(){
    	var time=$('#start').val()+","+ $('#end').val();
    	 $('#rptAdsTable').DataTable().column( 0 ).search(
// 		        $('#start').val()//开始时间
// 		       $('#end').val()//结束时间
    			 time
 		    ).draw();
    });
 //开始时间
  /*  $("#start").on( 'change', function () {
    	  $('#adsTable').DataTable().column( 0 ).search(
    		        $('#start').val()
    		    ).draw();
    } );
    //结束时间
    $("#end").on( 'change', function () {
  	  $('#adsTable').DataTable().column( 1 ).search(
  		        $('#end').val()
  		    ).draw();
  } );*/
    
 /*   var table = $('#adsTable').DataTable( {
        ajax: "data.json"
    } );
     
    table.on( 'xhr', function () {
        var json = table.ajax.json();
        alert( json.data.length +'row(s) were loaded' );
    } );*/
    
})($);